# This script loads the data for the Levada study

# respondent-level data
levada_resp <- read_rds("Data/levada_resp_data.rds") |>
  # recode presidential approval
  mutate(pres_approval_dummy = case_when(
    putin_approval %in% 2:3 ~ 1,
    putin_approval %in% 0:1 ~ 0
  ),
  pres_approval_cat = case_when(
    putin_approval == 0 ~ "Certainly disapprove",
    putin_approval == 1 ~ "Somewhat disapprove",
    putin_approval == 2 ~ "Somewhat approve",
    putin_approval == 3 ~ "Certainly approve"
  ),
  pres_approval_cat = factor(pres_approval_cat, 
                              levels = c("Certainly disapprove", 
                                         "Somewhat disapprove",
                                         "Somewhat approve", 
                                         "Certainly approve")),
  # recode voting choice in the 2018 presidential election
  vote_outcome_2018 = case_when(
    pres_election_voted == 1 & 
      voted_putin == 1 ~ "Putin",
    pres_election_voted == 1 & 
      voted_communist_nationalist == 1 ~ 
      "Communist/nationalist",
    pres_election_voted == 1 & 
      voted_liberal == 1 ~ "Liberal",
    (pres_election_voted == 1 & 
      pres_election_choice == "Spoiled") |
      pres_election_voted == 0 ~ "Spoiled ballot/no vote"),
  # create dummies for the usage of various news sources
  # (in the original variables, 0 means never)
  info_federal_state_tv_dummy = case_when(
    info_federal_state_tv %in% 2:4 ~ 1,
    info_federal_state_tv %in% 0:1 ~ 0
  ),
  # "online TV" in the survey meant TV Rain and RBC 
  # (by then, independent news outlets)
  info_online_tv_dummy = case_when(
    info_online_tv %in% 2:4 ~ 1,
    info_online_tv %in% 0:1 ~ 0
  ),
  info_foreign_websites_dummy = case_when(
    info_foreign_websites %in% 2:4 ~ 1,
    info_foreign_websites %in% 0:1 ~ 0
  ),
  # business press in the survey meant Forbes and Vedomosti
  # (by then, independent news outlets)
  info_info_business_press_dummy = case_when(
    info_business_press %in% 2:4 ~ 1,
    info_business_press %in% 0:1 ~ 0
  ),
  info_indep_media_dummy = case_when(
    info_online_tv_dummy == 1 | info_foreign_websites_dummy == 1 |
      info_info_business_press_dummy == 1 ~ 1,
    info_online_tv_dummy == 0 & info_foreign_websites_dummy == 0 &
      info_info_business_press_dummy == 0 ~ 0
  ))

# data on story evaluations
levada_stories <- read_rds("Data/levada_stories_data.rds") |>
  mutate(story_source_tv1 = case_when(
    story_source_tv1 == 1 ~ "Channel One",
    story_source_tv1 == 0 ~ "Echo of Moscow"
  ),
  story_source_tv1 = factor(story_source_tv1,
                            levels = c("Echo of Moscow", "Channel One")),
  # scale the responses/story evaluations to be between 0 and 1
  story_response_scaled = story_response/3) |>
  # join with respondent-level data
  left_join(levada_resp)
